using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;

namespace SpaceGame.ScreenInput
{
    public class ScreenPad
    {
        #region Fields and Properties
        TouchCollection touches;

        Vector2 LeftThumbPosition;
        Vector2 RightThumbPosition;

        Vector2 maxLeft;
        Vector2 minLeft;

        Vector2 maxRight;
        Vector2 minRight;

        /// <summary>
        /// The Value From the Left Stick. Vector2
        /// </summary>
        public Vector2 LeftStick
        {
            get
            {
                Vector2 scaledVector = (LeftThumbPosition - LeftThumbOriginalPosition) / (padTexture.Width / 2);
                scaledVector.Y *= -1;

                if (scaledVector.Length() > 1f)
                    scaledVector.Normalize();

                return scaledVector;
            }
            private set
            {

#if WINDOWS
                Vector2 hardStick = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left;
                LeftThumbPosition = hardStick * (padTexture.Width / 2) + LeftThumbPosition;
#endif

            }
        }

        /// <summary>
        /// The Value From the Right Stick. Vector2
        /// </summary>
        public Vector2 RightStick
        {
            get
            {
                Vector2 scaledVector = (RightThumbPosition - RightThumbOriginalPosition) / (padTexture.Width / 2);
                scaledVector.Y *= -1;
                if (scaledVector.Length() > 1f)
                    scaledVector.Normalize();

                return scaledVector;
            }
            private set
            {

#if WINDOWS
                Vector2 hardStick = GamePad.GetState(PlayerIndex.One).ThumbSticks.Right;
                RightThumbPosition = hardStick * (padTexture.Width / 2) + RightThumbOriginalPosition;
#endif

            }
        }

        Ray? ray;
        public Ray? ViewportRay
        {
            get { return ray; }
        }

        private Vector2 LeftThumbOriginalPosition;
        private Vector2 RightThumbOriginalPosition;

        private Vector2 LeftPadArea;
        private Vector2 LeftPadCenter;
        private Vector2 RightPadArea;
        private Vector2 RightPadCenter;

        private Vector2 fireButtonPosition;

        private Vector2 ButtonX;
        private Vector2 ButtonY;
        private Vector2 ButtonA;
        private Vector2 ButtonB;

        private float xOffset;
        private float yOffest;

        private Texture2D padTexture;
        private Texture2D thumbTexture;
        private Texture2D fireButton;

        private Texture2D abxyTexture;

        public Texture2D HealthBarTexture;
        public Texture2D HealthValueTexture;
        public bool DrawHealth;
        Vector2 screenOffset;
        Vector2 healthRectOffset;
        int currentHealthValue = 100;


        private Color LeftThumbColor;
        private Color RightThumbColor = Color.Red;
        private Color FireButtonColor;

        int leftId = -1;
        int rightId = -1;
        int fireId = -1;

        int xId = -1;
        int yId = -1;
        int aId = -1;
        int bId = -1;

        int rayId = -1;

        Color xColor;
        Color yColor;
        Color aColor;
        Color bColor;

        private BoundingSphere fireButtonCollision;

        private BoundingSphere leftStickCollision;
        private BoundingSphere rightStickCollision;

        private BoundingSphere xButtonCollision;
        private BoundingSphere yButtonCollision;
        private BoundingSphere aButtonCollision;
        private BoundingSphere bButtonCollision;

        float maxDistance;
        //TouchPanel screen;

        // weapon type for proper HUD selection
        /// <summary>
        /// Weapon Type for Proper HUD Selection
        /// </summary>
        public WeaponType CurrentWeapon
        {
            get { return currentWeapon; }
            set { currentWeapon = value; }
        }

        private WeaponType currentWeapon = WeaponType.Range;        

        public enum WeaponType
        {
            Meelee,
            Range,
            RangeAutoAim,
        }

        public bool FireButtonPressed { get; set; }

        ButtonState xPressed, yPressed, aPressed, bPressed = ButtonState.Released;
        Game game;
        
        bool XTYPE;

        private bool DualStickXType;

        #endregion

        public ScreenPad(Game game, Texture2D pad, Texture2D thumb, Texture2D fire,
            Color leftColor, Color rightColor, Color buttonColor)
        {
            this.game = game;

            padTexture = pad;
            thumbTexture = thumb;

            maxDistance = (padTexture.Width - 2 * thumbTexture.Width);

            fireButton = fire;

            // colors for sides 
            LeftThumbColor = leftColor;
            RightThumbColor = rightColor;
            FireButtonColor = buttonColor;
            // auto placement according to screen rotation
            PlaceControls();
        }

        /// <summary>
        /// Creates X360 type virtual Controler
        /// </summary>
        /// <param name="game">instance of game</param>
        /// <param name="pad">Texture for thumbstick base</param>
        /// <param name="thumb">Texture for thumbstick</param>
        /// <param name="abxyButtons">Texture for A, B, X, Y buttons. With size of 256x64 px with ABXY order.</param>
        public ScreenPad(Game game, Texture2D pad, Texture2D thumb, Texture2D abxyButtons)
        {
            this.game = game;

            padTexture = pad;
            thumbTexture = thumb;
            abxyTexture = abxyButtons;

            aColor = xColor = yColor = bColor = Color.LightGray;

            maxDistance = (padTexture.Width - thumbTexture.Width);
            XTYPE = true;
            LeftThumbColor = Color.White;
            RightThumbColor = Color.White;
            PlaceControls(true);
        }

        public ScreenPad(Game game, Texture2D pad, Texture2D thumb, Texture2D abxyButtons, bool dualStick)
            : this(game, pad, thumb, abxyButtons)
        {
            this.DualStickXType = true;
			PlaceControls(true);
        }

        private void PlaceControls(bool xType)
        {
            #region LeftStick
            xOffset = game.GraphicsDevice.Viewport.X + 30;
            yOffest = game.GraphicsDevice.Viewport.Height - padTexture.Height - 30;

            LeftPadArea = new Vector2(xOffset, yOffest);

            LeftPadCenter = new Vector2(
                LeftPadArea.X + padTexture.Width / 2,
                LeftPadArea.Y + padTexture.Height / 2);

            leftStickCollision = new BoundingSphere(new Vector3(LeftPadCenter, 0), padTexture.Width / 2);

            LeftThumbOriginalPosition = new Vector2(
                LeftPadArea.X + (padTexture.Width - thumbTexture.Width) / 2,
                LeftPadArea.Y + (padTexture.Height - thumbTexture.Height) / 2);

            minLeft = new Vector2(
                LeftPadCenter.X - padTexture.Width / 2 - thumbTexture.Width / 2,
                LeftPadCenter.Y - padTexture.Height / 2 - thumbTexture.Height / 2);

            maxLeft = new Vector2(
                LeftPadCenter.X + padTexture.Width / 2 - thumbTexture.Width / 2,
                LeftPadCenter.Y + padTexture.Height / 2 - thumbTexture.Height / 2);

            LeftThumbPosition = LeftThumbOriginalPosition;
            #endregion

            #region Right Stick
            xOffset = game.GraphicsDevice.Viewport.Width - (padTexture.Width + 30);
            yOffest = game.GraphicsDevice.Viewport.Height - (padTexture.Height + 30);

            // we already have the yOffset properly setup so use it from a few lines above

            RightPadArea = new Vector2(xOffset, yOffest);

            RightPadCenter = new Vector2(
                RightPadArea.X + padTexture.Width / 2,
                RightPadArea.Y + padTexture.Height / 2);

            rightStickCollision = new BoundingSphere(new Vector3(RightPadCenter, 0), padTexture.Width / 2);

            RightThumbOriginalPosition = new Vector2(
                RightPadArea.X + (padTexture.Width - thumbTexture.Width) / 2,
                RightPadArea.Y + (padTexture.Height - thumbTexture.Height) / 2);

            RightThumbPosition = RightThumbOriginalPosition;

            minRight = new Vector2(
                RightPadCenter.X - padTexture.Width / 2 - thumbTexture.Width / 2,
                RightPadCenter.Y - padTexture.Height / 2 - thumbTexture.Height / 2);

            maxRight = new Vector2(
                RightPadCenter.X + padTexture.Width / 2 - thumbTexture.Width / 2,
                RightPadCenter.Y + padTexture.Height / 2 - thumbTexture.Height / 2);
            #endregion

            #region Buttons

            if (DualStickXType)
            {
				RightPadCenter.Y -= 240;
				RightPadCenter.X -= 100;
            }
            
            ButtonX = new Vector2(RightPadCenter.X - 64f, RightPadCenter.Y);
            xButtonCollision = new BoundingSphere(new Vector3(new Vector2(ButtonX.X + 32f, ButtonX.Y + 32f), 0), 32f);
            ButtonY = new Vector2(RightPadCenter.X, RightPadCenter.Y - 64f);
            yButtonCollision = new BoundingSphere(new Vector3(new Vector2(ButtonY.X + 32f, ButtonY.Y + 32f), 0), 32f);
            ButtonA = new Vector2(RightPadCenter.X, RightPadCenter.Y + 64f);
            aButtonCollision = new BoundingSphere(new Vector3(new Vector2(ButtonA.X + 32f, ButtonA.Y + 32f), 0), 32f);
            ButtonB = new Vector2(RightPadCenter.X + 64f, RightPadCenter.Y);
            bButtonCollision = new BoundingSphere(new Vector3(new Vector2(ButtonB.X + 32f, ButtonB.Y + 32f), 0), 32f);
            
            #endregion
        }

        private void PlaceControls()
        {
            // left pad, it's always present and gives the direction for movement
            xOffset = game.GraphicsDevice.Viewport.X + 30;
            yOffest = game.GraphicsDevice.Viewport.Height - padTexture.Height - 30;

            LeftPadArea = new Vector2(xOffset, yOffest);

            LeftPadCenter = new Vector2(
                LeftPadArea.X + padTexture.Width / 2,
                LeftPadArea.Y + padTexture.Height / 2);

            leftStickCollision = new BoundingSphere(new Vector3(LeftPadCenter, 0), padTexture.Width / 2);

            LeftThumbOriginalPosition = new Vector2(
                LeftPadArea.X + (padTexture.Width - thumbTexture.Width) / 2,
                LeftPadArea.Y + (padTexture.Height - thumbTexture.Height) / 2);

            minLeft = new Vector2(
                LeftPadCenter.X - padTexture.Width / 2 - thumbTexture.Width / 2,
                LeftPadCenter.Y - padTexture.Height / 2 - thumbTexture.Height / 2);

            maxLeft = new Vector2(
                LeftPadCenter.X + padTexture.Width / 2 - thumbTexture.Width / 2,
                LeftPadCenter.Y + padTexture.Height / 2 - thumbTexture.Height / 2);

            LeftThumbPosition = LeftThumbOriginalPosition;

            // right thumb (when we have range weapons in arms)
            xOffset = game.GraphicsDevice.Viewport.Width - padTexture.Width - 30;

            // we already have the yOffset properly setup so use it from a few lines above

            RightPadArea = new Vector2(xOffset, yOffest);

            RightPadCenter = new Vector2(
                RightPadArea.X + padTexture.Width / 2,
                RightPadArea.Y + padTexture.Height / 2);

            rightStickCollision = new BoundingSphere(new Vector3(RightPadCenter, 0), padTexture.Width / 2);

            RightThumbOriginalPosition = new Vector2(
                RightPadArea.X + (padTexture.Width - thumbTexture.Width) / 2,
                RightPadArea.Y + (padTexture.Height - thumbTexture.Height) / 2);

            RightThumbPosition = RightThumbOriginalPosition;

            minRight = new Vector2(
                RightPadCenter.X - padTexture.Width / 2 - thumbTexture.Width / 2,
                RightPadCenter.Y - padTexture.Height / 2 - thumbTexture.Height / 2);

            maxRight = new Vector2(
                RightPadCenter.X + padTexture.Width / 2 - thumbTexture.Width / 2,
                RightPadCenter.Y + padTexture.Height / 2 - thumbTexture.Height / 2);

            // and finally the fire button when we have meelee or auto aim arms
            xOffset = game.GraphicsDevice.Viewport.Width - fireButton.Width - 30;
            yOffest = game.GraphicsDevice.Viewport.Height - fireButton.Height - 30;

            fireButtonPosition = new Vector2(
                RightPadCenter.X - fireButton.Width / 2,
                RightPadCenter.Y - fireButton.Height / 2); //new Vector2(xOffset, yOffest);

            fireButtonCollision = new BoundingSphere(new Vector3(RightPadCenter, 0), fireButton.Width / 2);

            //xButtonCollision = new BoundingSphere()
        }

        public void Draw(SpriteBatch spriteBatch)
        {
			//if (game.IsPaused || game.IsGameOver)
			//    return;

            

            Vector2 currentLeftPosition = new Vector2(
                LeftThumbOriginalPosition.X + LeftStick.X * maxDistance,
                LeftThumbOriginalPosition.Y + LeftStick.Y * maxDistance * -1);

            // left thumb we always draw 
            spriteBatch.Draw(padTexture, LeftPadArea, (leftId == -1) ? LeftThumbColor : Color.CornflowerBlue);
            spriteBatch.Draw(thumbTexture, currentLeftPosition, LeftThumbColor);

			//if (DrawHealth)
			//{
			//    spriteBatch.Draw(HealthBarTexture, screenOffset, Color.White);
			//    spriteBatch.Draw(HealthValueTexture, (screenOffset + healthRectOffset), new Rectangle(0, 0, game.mainChar.Health * 2, HealthValueTexture.Height), Color.White);
			//}

            

            #region X360 Typed Controls

            if (XTYPE)
            {
                if (DualStickXType)
                {
                    Vector2 currentRightPosition = new Vector2(
                            RightThumbOriginalPosition.X + RightStick.X * maxDistance,
                            RightThumbOriginalPosition.Y + RightStick.Y * maxDistance * -1);

                    spriteBatch.Draw(padTexture, RightPadArea, (rightId == -1) ? RightThumbColor : Color.Red);
                    spriteBatch.Draw(thumbTexture, currentRightPosition, RightThumbColor);
                }
				//else
				//{
                spriteBatch.Draw(abxyTexture, ButtonA, new Rectangle(0, 0, 64, 64), aColor);
                spriteBatch.Draw(abxyTexture, ButtonB, new Rectangle(64, 0, 64, 64), bColor);
                spriteBatch.Draw(abxyTexture, ButtonX, new Rectangle(128, 0, 64, 64), xColor);
                spriteBatch.Draw(abxyTexture, ButtonY, new Rectangle(192, 0, 64, 64), yColor);
				//}
                
            }
            #endregion

            #region This is not X360 type controls
            else
            {
                
                switch (currentWeapon)
                {
                    case WeaponType.Meelee:
                        spriteBatch.Draw(fireButton, fireButtonPosition, FireButtonColor);
                        break;

                    case WeaponType.Range:
                        Vector2 currentRightPosition = new Vector2(
                            RightThumbOriginalPosition.X + RightStick.X * maxDistance,
                            RightThumbOriginalPosition.Y + RightStick.Y * maxDistance * -1);

                        spriteBatch.Draw(padTexture, RightPadArea, RightThumbColor);
                        spriteBatch.Draw(thumbTexture, currentRightPosition, RightThumbColor);

                        break;

                    case WeaponType.RangeAutoAim:
                        spriteBatch.Draw(fireButton, fireButtonPosition, FireButtonColor);

                        break;
                }
                
            }
            #endregion
        }

        public void Update()
        {
#if WINDOWS_PHONE
            TouchLocation? leftTouch = null;
            TouchLocation? rightTouch = null;
            TouchLocation? fireTouch = null;

            TouchLocation? xTouch = null;
            TouchLocation? yTouch = null;
            TouchLocation? aTouch = null;
            TouchLocation? bTouch = null;

            TouchLocation? rayTouch = null;

            touches = TouchPanel.GetState();

            foreach (var t in touches)
            {
                #region Left stick is always updated
                if (t.Id == leftId)
                {
                    leftTouch = t;
                    continue;
                }

                if (leftId == -1)
                {
                    if (IsTouchingLeftStick(t.Position))
                    {
                        leftTouch = t;
                        continue;
                    }
                }
                #endregion
                #region XTYPE OR NOT

                if (XTYPE)
                {
                    // if dualstick xType update right stick
                    if (DualStickXType)
                    {
                        if (t.Id == rightId)
                        {
                            rightTouch = t;
                            continue;
                        }
                        if (rightId == -1)
                        {
                            if (IsTouchingRightStick(t.Position))
                            {
                                rightTouch = t;
                                continue;
                            }
                        }
                    }

                    #region X button
                    if (t.Id == xId)
                    {
                        xTouch = t;
                        continue;
                    }
                    if (xId == -1)
                    {
                        if (IsTouchingButton(t.Position, xButtonCollision))
                        {
                            xTouch = t;
                            continue;
                        }
                    }
                    #endregion
                    #region Y button
                    if (t.Id == yId)
                    {
                        yTouch = t;
                        continue;
                    }
                    if (yId == -1)
                    {
                        if (IsTouchingButton(t.Position, yButtonCollision))
                        {
                            yTouch = t;
                            continue;
                        }
                    }
                    #endregion
                    #region A button
                    if (t.Id == aId)
                    {
                        aTouch = t;
                        continue;
                    }
                    if (aId == -1)
                    {
                        if (IsTouchingButton(t.Position, aButtonCollision))
                        {
                            aTouch = t;
                            continue;
                        }
                    }
                    #endregion
                    #region B button
                    if (t.Id == bId)
                    {
                        bTouch = t;
                        continue;
                    }
                    if (bId == -1)
                    {
                        if (IsTouchingButton(t.Position, bButtonCollision))
                        {
                            bTouch = t;
                            continue;
                        }
                    }
                    #endregion
                }
                else
                {

                    if (CurrentWeapon == WeaponType.Range)
                    {
                        if (t.Id == rightId)
                        {
                            rightTouch = t;
                            continue;
                        }
                        if (rightId == -1)
                        {
                            if (IsTouchingRightStick(t.Position))
                            {
                                rightTouch = t;
                                continue;
                            }
                        }
                    }
                    else
                    {
                        if (t.Id == fireId)
                        {
                            fireTouch = t;
                            continue;
                        }
                        if (fireId == -1)
                        {
                            if (IsTouchingFireButtom(t.Position))
                            {
                                fireTouch = t;
                                continue;
                            }
                        }
                    }
                }
                #endregion
                #region Viewport Picking
                if (t.Id == rayId)
                {
                    rayTouch = t;
                    continue;
                }

                if (rayId == -1)
                {
                    if (
                        !IsTouchingLeftStick(t.Position) &&
                        !IsTouchingRightStick(t.Position) &&
                        !IsTouchingFireButtom(t.Position) &&
                        !IsTouchingButton(t.Position, xButtonCollision) &&
                        !IsTouchingButton(t.Position, yButtonCollision) &&
                        !IsTouchingButton(t.Position, aButtonCollision) &&
                        !IsTouchingButton(t.Position, bButtonCollision)
                    )
                    {
                        rayTouch = t;
                        continue;
                    }
                }
                #endregion
            }

            #region Left Stick
            if (leftTouch.HasValue)
            {
                LeftThumbPosition = new Vector2(
                    leftTouch.Value.Position.X - thumbTexture.Width / 2,
                    leftTouch.Value.Position.Y - thumbTexture.Height / 2);

                LeftThumbPosition = Vector2.Clamp(LeftThumbPosition, minLeft, maxLeft);
                leftId = leftTouch.Value.Id;
            }
            else
            {
                leftId = -1;
                LeftThumbPosition += (LeftThumbOriginalPosition - LeftThumbPosition) * 0.9f;
            }
            #endregion
            #region Right Stick
            if (rightTouch.HasValue)
            {
                RightThumbPosition = new Vector2(
                    rightTouch.Value.Position.X - thumbTexture.Width / 2,
                    rightTouch.Value.Position.Y - thumbTexture.Height / 2);

                RightThumbPosition = Vector2.Clamp(RightThumbPosition, minRight, maxRight);
                rightId = rightTouch.Value.Id;
            }
            else
            {
                rightId = -1;
                RightThumbPosition += (RightThumbOriginalPosition - RightThumbPosition) * 0.9f;
            }
            #endregion
            #region fireTouch
            if (fireTouch.HasValue)
            {
                FireButtonPressed = true;
            }
            else
            {
                fireId = -1;
                FireButtonPressed = false;
            }
            #endregion

            #region x Touch
            if (xTouch.HasValue)
            {
                xPressed = ButtonState.Pressed;
                xColor = Color.White;
            }
            else
            {
                xId = -1;
                xPressed = ButtonState.Released;
                xColor = Color.LightGray;
            }
            #endregion
            #region y Touch
            if (yTouch.HasValue)
            {
                yPressed = ButtonState.Pressed;
                yColor = Color.White;
            }
            else
            {
                yId = -1;
                yPressed = ButtonState.Released;
                yColor = Color.LightGray;
            }
            #endregion
            #region a Touch
            if (aTouch.HasValue)
            {
                aPressed = ButtonState.Pressed;
                aColor = Color.White;
            }
            else
            {
                aId = -1;
                aPressed = ButtonState.Released;
                aColor = Color.LightGray;
            }
            #endregion
            #region b Touch
            if (bTouch.HasValue)
            {
                bPressed = ButtonState.Pressed;
                bColor = Color.White;
            }
            else
            {
                bId = -1;
                bPressed = ButtonState.Released;
                bColor = Color.LightGray;
            }
            #endregion
            #region ray
            if (rayTouch.HasValue)
            {
                // cast the ray
                //ray = CalculateCursorRay(rayTouch.Value.Position, game.camera.Projection, game.camera.View);
            }
            else
            {
                rayTouch = null;
                rayId = -1;
                ray = null;
            }
            #endregion
#endif
            #region Windows Controls. This controls the virtual thumbsticks
#if WINDOWS
            GamePadState state = GamePad.GetState(PlayerIndex.One);

            Vector2 lft = state.ThumbSticks.Left;
            lft.Y *= -1;
            Vector2 rght = state.ThumbSticks.Right;
            rght.Y *= -1;

            LeftThumbPosition = LeftThumbOriginalPosition + lft * (padTexture.Width / 2);
            
            RightThumbPosition = RightThumbOriginalPosition + rght * (padTexture.Width / 2);
#endif
            #endregion
        }

        private bool IsTouchingLeftStick(Vector2 point)
        {
            ContainmentType t = leftStickCollision.Contains(new Vector3(point, 0));
            return (t == ContainmentType.Contains);
        }

        private bool IsTouchingRightStick(Vector2 point)
        {
            ContainmentType t = rightStickCollision.Contains(new Vector3(point, 0));
            return (t == ContainmentType.Contains);
        }

        private bool IsTouchingFireButtom(Vector2 point)
        {
            ContainmentType t = fireButtonCollision.Contains(new Vector3(point, 0));
            return (t == ContainmentType.Contains);
        }

        private bool IsTouchingButton(Vector2 point, BoundingSphere buttonBounds)
        {
            ContainmentType t = buttonBounds.Contains(new Vector3(point, 0));
            return (t == ContainmentType.Contains);
        }

        // CalculateCursorRay Calculates a world space ray starting at the camera's
        // "eye" and pointing in the direction of the cursor. Viewport.Unproject is used
        // to accomplish this. see the accompanying documentation for more explanation
        // of the math behind this function.
        public Ray CalculateCursorRay(Vector2 position, Matrix projectionMatrix, Matrix viewMatrix)
        {
            // create 2 positions in screenspace using the cursor position. 0 is as
            // close as possible to the camera, 1 is as far away as possible.
            Vector3 nearSource = new Vector3(position, 0f);
            Vector3 farSource = new Vector3(position, 1f);

            // use Viewport.Unproject to tell what those two screen space positions
            // would be in world space. we'll need the projection matrix and view
            // matrix, which we have saved as member variables. We also need a world
            // matrix, which can just be identity.
            Vector3 nearPoint = game.GraphicsDevice.Viewport.Unproject(nearSource,
                projectionMatrix, viewMatrix, Matrix.Identity);

            Vector3 farPoint = game.GraphicsDevice.Viewport.Unproject(farSource,
                projectionMatrix, viewMatrix, Matrix.Identity);

            // find the direction vector that goes from the nearPoint to the farPoint
            // and normalize it....
            Vector3 direction = farPoint - nearPoint;
            direction.Normalize();

            // and then create a new ray using nearPoint as the source.
            return new Ray(nearPoint, direction);
        }

        /// <summary>
        /// Returns the ScreenPad state
        /// State consists of Thumbsticks and ABXY buttons
        /// More buttons will be added later
        /// </summary>
        /// <returns>ScreenPadState</returns>
        public ScreenPadState GetState()
        {
            return new ScreenPadState 
            ( 
                new ThumbSticks 
                (
                    LeftStick, 
                    RightStick
                ), 
                new Buttons 
                (
                    aPressed,
                    bPressed,
                    xPressed,
                    yPressed
                ) 
            );
        }

        public void BuildHud(Texture2D mask, Texture2D health, Vector2 position)
        {
            HealthBarTexture = mask;
            HealthValueTexture = health;
            screenOffset = position;
            healthRectOffset = new Vector2((HealthBarTexture.Width - HealthValueTexture.Width) / 2, (HealthBarTexture.Height - HealthValueTexture.Height) / 2);
            DrawHealth = true;
        }

        public void UpdateHealth(int newValue)
        {
            currentHealthValue = (int)MathHelper.Lerp(currentHealthValue, newValue, 0.2f);
        }
    }
}
